package pay.controller;


import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.tags.Tags;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import pay.service.RefundLogicService;
import pay.utils.R;

import java.util.Map;

@RestController
@Tags(value = {@Tag(name = "退款模块", description = "退款")})
@RequestMapping("/refund")
public class RefundController {

    @Autowired
    RefundLogicService wechatRefundLogicService;

    @RequestMapping(value = "callback", method = {RequestMethod.POST, RequestMethod.GET})
    public R refundCallback(@RequestBody Map<String, Object> data) {
        try {
            wechatRefundLogicService.callback(data);
            return R.ok(
                    "<xml>\n" +
                            "  <return_code><![CDATA[SUCCESS]]></return_code>\n" +
                            "  <return_msg><![CDATA[OK]]></return_msg>\n" +
                            "</xml>\n"
            );
        } catch (Exception e) {
            e.printStackTrace();
            return R.ok(
                    "<xml>\n" +
                            "  <return_code><![CDATA[FAIL]]></return_code>\n" +
                            "  <return_msg><![CDATA[签名失败]]></return_msg>\n" +
                            "</xml>\n"
            );
        }
    }

}
